<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>风味-个人资料</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/personCenterPublic.css"/>
		<link rel="stylesheet" type="text/css" href="css/personInfo.css"/>
		<script src="js/jquery-2.1.0.js"></script>
		<script>
//	<!-- 在跳转页面，特别是返回页面的时候需注意：返回的不是一个单纯的原来的页面，而是带着id的页面，跳转的时候也一样，所以都需要用js来控制跳转-->
			$(function(){
				var str=location.href; //获取本页url地址
				var arr=str.split("?");
				var str1 = arr[1];
				var userIdString = str1.split("=")[1];
				var userId = parseInt(userIdString);
				$.ajax("/fengwei/user/setNameAndPhone",{
					type:"get",
					data:{
						//传送id给后台
						"userId":userId
					},
//						async : false,
					success:function(data){
						var dataObj = eval('('+data+')');
//						console.log(data)
						$('#nickname').val(dataObj.userNikename);
						$("#phone").val(dataObj.userPhone);
						$("#school").val(dataObj.userSchool);
						$("#userId").val(dataObj.userId)
					},
					error:function(data){
//							提交不成功
						console.log(data);
					}
				})

				var oBtn = $("#submitAlter");
				oBtn.click(function(){
					var getNickname = $('#nickname').val();
					var getPhone = $("#phone").val();
					var getUserSchool = $("#school").val();

					$.ajax("/fengwei/user/update",{
						type:"post",
						data:{
							'userId':userId,
							'userNikename':getNickname,
							'userPhone':getPhone,
							'userSchool':getUserSchool
						},
						success:function(){
							alert(1)
						},
						error:function(){
							alert(0)
						}
					})
				});

				var change = $("#nextPage")
				var change2 = $("#nextPage2")
				change.click(function(){
					window.location.href = "originPwd.html?userId="+userId+"";
				})
				change2.click(function(){
					window.location.href = "address.html?userId="+userId+"";
				})

				$.ajax("/fengwei/user/getImg",{
					type:"get",
					data:{},
					success:function(data){
						var dataObj = eval('('+data+')');
						console.log(dataObj);
						var arr = dataObj.fileUrl.split("\\");
						var src = arr[arr.length-2]+"/"+arr[arr.length-1];
						var img = document.getElementById('img');
						img.src = src;
					},
					error:function(){

					}
				});

			})
		</script>
	</head>
	<body>
		<div id="back">
			<a href="#" onClick="javascript :history.back(-1);"><&nbsp;返回个人中心</a>
		</div>
			<div id="headImg" onclick="alterImg()">
				&nbsp;您的头像：
				<a href="####"><img src="img/bing.jpg" id="img"/></a>
			</div>
		<form action="" method="post" id="alterPersonInfo">
			<label for="nickname">&nbsp;昵称：</label><span class="border_bottom"><input type="text" name="nickname" id="nickname"placeholder="" value="风味四小只"/></span><br />
			<label for="userId">&nbsp;用户ID:</label><span class="border_bottom"><input type="text" name="userId" id="userId" value="123" onclick="alterId()"/></span><br />
			<label for="phone">&nbsp;电话号码：</label><span class="border_bottom"><input type="text" name="phone" id="phone" value="12345678910"/></span><br />
			<label for="phone">&nbsp;学校：</label><span class="border_bottom"><input type="text" name="school" id="school" value="四川"/></span><br />
			<!-- hbl--删除链接--修改为js控制跳转---加一个id-->
			<a id="nextPage" class="nextPage" target="_blank">&nbsp;修改密码&nbsp;&nbsp;<span class="jiantou">></span></a>
			<a id="nextPage2" class="nextPage" target="_blank">&nbsp;收货地址管理<span class="jiantou">></span></a>
			<span id="color"><input type="button" value="确认修改" id="submitAlter" style="background:none;color: white;font-size: 18px;"/></span><br />
		</form>
		<script type="text/javascript">
			function alterId(){//用户要修改系统分配的id时
			alert('用户ID是系统分配，不能修改！');
			var userId=document.getElementById('userId');
			userId.disabled=true;
			}
			function alterImg(){
				window.open('alterImg.html');
			}

			var nickname1=document.getElementById('nickname');//以下是按钮的改变
			var number1=document.getElementById('phone');
			var school1=document.getElementById('school');
			var color1=document.getElementById('color');
			nickname1.oninput=number1.oninput=school1.oninput=function(){
				color1.style.background='#ffcc00';
			}


		</script>
	</body>
</html>
